/**
 * 
 */
package com.block.common.security.service.impl;


import com.block.common.security.service.AppEncryptMannerService;
import com.block.common.security.util.AESUtil;
import com.block.db.entity.AppEncrypt;

import java.io.UnsupportedEncodingException;


/**
 * 
 * AES加密方式
 */
public class AESEncryptManner implements AppEncryptMannerService {
	
	//加密
	@Override
	public String encode(AppEncrypt appEncrypt, String tranData, String cipherKey) {
		return AESUtil.parseByte2HexStr(AESUtil.encrypt(tranData, cipherKey));
	}

	//解密
	@Override
	public String decode(AppEncrypt appEncrypt, String tranData, String cipherKey) {
		byte[] decryptFrom = AESUtil.parseHexStr2Byte(tranData);  
		byte[] decryptResult = AESUtil.decrypt(decryptFrom, cipherKey);
		//解密后数据【AES】
		try {
			return new String (decryptResult, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
	

}
